package com.ywqf_api.service.impl;

import com.ywqf_api.dao.MessageDao;
import com.ywqf_api.entity.Message;
import com.ywqf_api.entity.MessageUser;
import com.ywqf_api.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2018/4/2 0002.
 */
@Service
public class MessageServiceImpl implements MessageService {
    @Autowired
    private MessageDao messageDao;

    @Override
    public List<Message> findMessage(Integer customerId, Integer communityId) {
        List<Message> list = messageDao.findMessage(customerId,communityId);
        if(list.size() > 0){
            for(int i=0;i<list.size();i++){
                Message message = list.get(i);
                if(message.getReleaseTime().length() >= 19){
                    message.setReleaseTime(message.getReleaseTime().substring(0,19));
                }
            }
            return list;
        }else{
            return null;
        }
    }

    @Override
    public MessageUser findUser(Integer releaseUserId, Integer communityId) {
        MessageUser messageUser = messageDao.findUser(releaseUserId,communityId);
        if(messageUser == null){
            return null;
        }else{
            return messageUser;
        }
    }

    @Override
    public Message findMessageOne(Integer publicityId) {
        Message message = messageDao.findMessageOne(publicityId);
        if(message != null){
            if(message.getReleaseTime().length()>=19){
                message.setReleaseTime(message.getReleaseTime().substring(0,19));
            }
        }
        return message;
    }
}
